package PolladminFunc;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import PollcreatorFunc.Pollcreator;

public class PollcreatorMgt extends HttpServlet {

	private static final long serialVersionUID = -4665366296368213035L;

	public PollcreatorMgt(){
		super();
	}
	
	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session=request.getSession(true);
		String username=request.getParameter("username");
		String email=request.getParameter("email");
		String fname=request.getParameter("fname");
		String lname=request.getParameter("lname");
		
		Pollcreator pct=new Pollcreator();
		pct.setUsername(username);
		pct.setPassword(RandomStringUtils.random(6,true,true));
		pct.setEmail(email);
		pct.setAccessibility(3);
		pct.setFname(fname);
		pct.setLname(lname);
		PollcreatorDAO pctd=new PollcreatorDAO();
		pctd.add(pct);
		response.sendRedirect("pollcreator.jsp");
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}
	
}
